package com.example.hello;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

public class CondigActivity extends AppCompatActivity {
    public  static  final  String TAG="config";
    String d;
    String e;
    String w;
    private EditText dollar_key;
    private EditText euro_key;
    private EditText won_key;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_condig);
        Log.i(TAG,"oncreat:------");

        //接受
        Intent intent = getIntent();
        float dollar=intent.getFloatExtra("dollar_key",0.0f);
        float euro=intent.getFloatExtra("euro_key",0.0f);
        float won=intent.getFloatExtra("won_key",0.0f);

        Log.i(TAG,"dollar_key"+dollar);
        Log.i(TAG,"euro_key"+euro);
        Log.i(TAG,"won_key"+won);

        dollar_key=findViewById(R.id.dollar_key);
        d=Float.toString(dollar);
        euro_key=findViewById(R.id.euro_key);
        e=Float.toString(euro);
        won_key=findViewById(R.id.won_key);
        w=Float.toString(won);

        //把数据放入到页面控件中
        dollar_key.setText(d);
        //dollar_key.setText(String.valueOf(dollar);
        euro_key.setText(e);
        won_key.setText(w);

    }
    public void save(View btn){
        //获取用户修改数据
        d=dollar_key.getText().toString();
        Float dollar_new=Float.parseFloat(d);
        e=euro_key.getText().toString();
        Float euro_new=Float.parseFloat(e);
        w=won_key.getText().toString();
        Float won_new=Float.parseFloat(w);


        //带回数据
        Intent intent=getIntent();
        Bundle bundle=new Bundle();
        bundle.putFloat("dollar_new",Float.parseFloat(d));
        bundle.putFloat("euro_new",Float.parseFloat(e));
        bundle.putFloat("won_new",Float.parseFloat(w));
        intent.putExtras(bundle);

        setResult(6,intent);

        finish();

//        //返回原来窗口
//        Intent intent=new Intent(this,RateActivity.class);
//        intent.putExtra("dollar_new",dollar_new);
//        intent.putExtra("euro_new",euro_new);
//        intent.putExtra("won_new",won_new);
//
//        Log.i(TAG,"openOne:dollarRate="+dollar_new);
//        Log.i(TAG,"openOne:euroRate="+euro_new);
//        Log.i(TAG,"openOne:wonRate="+won_new);
//        startActivity(intent);
    }
}